/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    struct ListNode* dummy = (struct ListNode*)malloc(sizeof(struct ListNode));
    dummy->next = NULL;
    struct ListNode* cur = head;
    if(!head || !head->next) return head;
    while(head) {
        head = head->next;
        cur->next = dummy->next;
        dummy->next = cur;
        cur = head;
    }
    return dummy->next;
}